package userlogic

import (
	"context"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/service"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BalanceDecreaseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBalanceDecreaseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BalanceDecreaseLogic {
	return &BalanceDecreaseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BalanceDecreaseLogic) BalanceDecrease(in *rpc.BalanceDecreaseRequest) (*rpc.BalanceDecreaseRespone, error) {
	if in.Amount < 0 {
		return nil, xerrors.ErrInvalidParameterAmount
	}
	if in.ValidConsume < 0 {
		return nil, xerrors.ErrInvalidParameterValidConsume
	}

	ret, err := service.BalanceDecrease(l.ctx, l.svcCtx, in)
	if err != nil {
		return nil, err
	}
	return ret, nil
}
